package com.yfp.operation.mqtt;

import cn.hutool.core.util.ReUtil;
import cn.hutool.core.util.StrUtil;
import com.yfp.common.mqtt.model.ChannelName;
import com.yfp.operation.service.DeviceService;
import org.springframework.integration.annotation.ServiceActivator;
import org.springframework.messaging.Message;
import org.springframework.stereotype.Service;

import jakarta.annotation.Resource;

/**
 * MQTT消息处理器（消费者）
 * 处理接收到的消息
 */
@Service
public class MqttService {

    @Resource
    private DeviceService deviceService;

    @ServiceActivator(inputChannel = ChannelName.CHANNEL_NAME_IN)
    public void receiveMessage(Message<String> message) {
        String topic = message.getHeaders().get("mqtt_receivedTopic").toString();
        String deviceNum = ReUtil.getGroup1("machine/(\\w+)/offline", topic);
        if (StrUtil.isBlank(deviceNum)) {
            return;
        }
    }
}
